package com.hellobike.haxing.modules.wms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hellobike.haxing.modules.wms.dto.OrderDetailDto;
import com.hellobike.haxing.modules.wms.dto.OrderHeaderDto;
import com.hellobike.haxing.modules.wms.entity.DeliveryOrderHeader;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Description: t_wms_delivery_order_header
 * @Author: haxing-boot
 * @Date:   2020-01-14
 * @Version: V1.0
 */
public interface DeliveryOrderHeaderMapper extends BaseMapper<DeliveryOrderHeader> {

    @Select("SELECT o.id,o.bill_no,o.user_id,o.shop_id FROM t_order_b as b " +
            "LEFT JOIN t_order as o ON b.order_id=o.\"id\" " +
            "WHERE b.deleted=0 AND o.deleted=0 AND o.is_async=0 AND o.status=3  " +
            "AND o.success_time is not null AND o.success_time<=NOW()")
    List<OrderHeaderDto> getUnSyncOrders();

    @Select("SELECT d.sku_id,d.num as qty FROM t_order_detail as d WHERE d.order_id =#{orderId}")
    List<OrderDetailDto> getOrderDetailByOrderId(@Param("orderId") Long orderId);

    @Update("UPDATE t_order SET is_async=1,sync_time=NOW() WHERE \"id\"=#{id}")
    void updateSyncOrder(@Param("id") Long id);
}
